cmake_minimum_required(VERSION 3.12.1)
project(calculator_tests)

# 启用测试
enable_testing()

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 启用覆盖率（可选）
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")

# 引入 FetchContent 模块
include(FetchContent)

# 下载 GoogleTest
FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/refs/heads/main.zip
)

# 可选：避免安装文档和示例
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# 使其可用
FetchContent_MakeAvailable(googletest)

# 包含主项目头文件
include_directories(${CMAKE_SOURCE_DIR}/../src/include)

# 添加测试目标
add_executable(test_calculator test_calculator.cpp ../src/calculator.cpp)

# 链接 GoogleTest
target_link_libraries(test_calculator gtest_main)

# 注册测试
# add_test(NAME CalculatorTest COMMAND test_calculator)

# 注册测试
include(GoogleTest)
gtest_discover_tests(test_calculator)
